<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Points;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class PointsController extends Controller
{
    public function getList(Request $request)
    {
        $rule = [
            'uuid' => 'required|string',
        ];
        $message = [
            'uuid.required' => 'uuid不能为空',
        ];

        $valid = Validator::make($request->all(), $rule, $message);
        if ($valid->fails()) {
            $this->code = 1;
            $this->msg = $valid->errors()->first();
            return $this->json();
        }
        $model = new Points();
        $where[] = ['status','<',99];

        if(isset($request->type) && !empty($request->type)){
            $where[] = ['type' ,$request->type];
        }
        if (isset($request->uuid) && $request->uuid != ''){
            $where[] = ['uuid' ,$request->uuid];
        }

        $model->data['num'] = $request->num;
        $model->data['page'] = $request->page;
        $model->data['where'] = $where;
        $model->data['select'] = 'id,type,total,note,do_time,balance';
        $this->data = $model->getList();
        return $this->json();
    }

}
